<?php

class Cms_NewscateController extends H_Controller_Cms_ActionExtent
{    
    public function  init() {
        parent::init();
        $this->entityOb = new H_News_Entity();
        $this->cateOb = new H_News_Cate();
        $this->entity_cateOb = new H_News_EntityCate();
    }
    public function indexAction()
    {        
    	$this->view->list = $this->cateOb->fetchAll();
    }
    public function entityAction()
    {        
        $id = $this->_request->getParam('id',-1);       
        if ($id!=-1){
            $currentItem = $this->cateOb->find($id)->toArray();
            $this->view->currentItem = $currentItem[0];
            $this->view->act = H_G::EDIT;
            $this->view->lg = $currentItem[0]['lang'];
        }else{
            $this->view->act = H_G::ADD;
            $lg = $this->_request->getParam('lg',H_G::$DEFAULT_LANG);
            $this->view->lg = $lg;
        }

        if ($this->_request->isPost()){
            $data = $this->_request->getParams();
            
            if ($this->_request->getParam("act")==H_G::ADD){
                $this->cateOb->add($data);
                $this->_redirect ("/cms/".$this->_request->getControllerName());
            }elseif($this->_request->getParam("act")==H_G::EDIT){
                $this->cateOb->edit($id, $data);
                $this->_redirect ("/cms/".$this->_request->getControllerName());
            }
        }
        
    }
   

    public function sampledataAction(){
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $filename = $this->_request->getParam('file','default');
        $filePath = BASE_PATH.'/sampledata/'.$this->_request->getControllerName().'/'.$filename.".html";
        
        $content = '';
        if (file_exists($filePath))
                $content = file_get_contents($filePath);
        echo $content;
    }

    protected function  getProperties() {
        return array(
            H_Description::PAGE_TITLE => $this->view->t('Phan nhom tin tuc'),
            H_Description::TITLE => array(
                H_Description::LABLE => $this->view->t('tieu de phan loai'),
                H_Description::CLASST=> H_Description::LONGTEXT ." ". H_Description::REQUIRED,
//              H_Description::REQUIRED_TEXT => 'Khong nhap khong duoc'
            ),
            H_Description::LANG  => array(
                H_Description::LABLE => $this->view->t('ngon ngu'),
                H_Description::CLASST=> H_Description::REQUIRED,
            ),
            H_Description::ORDER  => array(
                H_Description::LABLE => $this->view->t('thu tu hien thi'),
                H_Description::CLASST => H_Description::NUMBER,
            ),
            H_Description::STATUS => array(
                H_Description::LABLE => $this->view->t('trang thai'),                
            ),
//            H_Description::KEYWORD => array(
//                H_Description::LABLE => $this->view->t('thuoc thanh phan sau'),
//                H_Description::CLASST => H_Description::REQUIRED,
//                H_Description::REQUIRED_TEXT => 'phai chon nha con'
//            ),
            H_Description::CATEGORIES => array(
                H_Description::LABLE => $this->view->t('phan loai cha'),
                H_Description::ACTION => 'get-cate',//Action to get categories
                H_Description::CONTROLLER => $this->_request->getControllerName(),
                H_Description::MODULE => $this->_request->getModuleName(),
                H_Description::CLASST => H_Description::REQUIRED,
                H_Description::REQUIRED_TEXT => $this->view->t('Co the chon mot hoac nhieu phan loai tin'),
                H_Description::CATE_SHOW_TYPE => H_Description::CATE_SHOW_COMBOBOX,
                H_Description::SHOW_FOR => H_Description::CATEGORIES
            ),
//            'img' => array(
//                H_Description::TITLE => $this->view->t('thong tin hinh anh'),
//                'img1' => array(
//                    H_Description::LABLE => $this->view->t('Hinh anh tin tuc'),
//                    H_Description::CLASST => H_Description::REQUIRED,
//                    H_Description::REQUIRED_TEXT => $this->view->t('Hinh hien thi tren trang chu.')
//                ),
//                'img2' => array(
//                    H_Description::LABLE => $this->view->t('Img 2'),
//                    H_Description::CLASST => '',
//                ),
//            ),

//            'f' => array(
//                H_Description::TITLE => $this->view->t('file dinh kem'),
//                'f1' => array(
//                    H_Description::LABLE => $this->view->t('F 1'),
//                    H_Description::CLASST => '',
//                ),
//                'f2' => array(
//                    H_Description::LABLE => $this->view->t('F 2'),
//                    H_Description::CLASST => H_Description::REQUIRED,
//                    H_Description::REQUIRED_TEXT => $this->view->t('File dinh kem neu co'),
//                ),
//            ),
//            'p' => array(
//                H_Description::TITLE => $this->view->t('cac thong tin khac'),
//                'p1' => array(
//                    H_Description::LABLE => $this->view->t('thuoc tinh p1'),
//                    H_Description::CLASST => H_Description::TEXT,
//                ),
//                'p2' => array(
//                    H_Description::LABLE => $this->view->t('thuoc tinh p2'),
//                    H_Description::CLASST => H_Description::LONGTEXT,
//                ),
//            ),
            'sr' => array(
                H_Description::TITLE => $this->view->t('thong tin so luoc'),
                'sr1' => array(
                    H_Description::LABLE => $this->view->t('Mo ta ngan'),
                    H_Description::CLASST => H_Description::REQUIRED,
//                  H_Description::REQUIRED_TEXT => $this->view->t('Hien thi tren trang chu.'),
                ),
//                'sr2' => array(
//                    H_Description::LABLE => $this->view->t('Short Des2'),
//                    H_Description::CLASST => '',
//                ),
            ),
            'r' => array(
                H_Description::TITLE => $this->view->t('mo ta chi tiet phan loai tin tuc'),
                'r1' => array(
                    H_Description::LABLE => $this->view->t('Chi tiet phan loai'),
                    H_Description::CLASST => '', //H_Description::REQUIRED,
//                    H_Description::REQUIRED_TEXT => $this->view->t('Chi tiet tin tuc'),
                    H_Description::EDITOR_TYPE => H_View_Helper_Editor::BASIC_TYPE,
                    H_Description::SAMPLEDATA => '/cms/newscate/sampledata'
                ),
//                'r2' => array(
//                    H_Description::LABLE => $this->view->t('R2'),
//                    H_Description::CLASST => '',
//                )
            ),
        );
    }
    protected function  getPropertiesOrderList() {
        return array(
            'col1' => array(
                    'title' => $this->view->t('tieu de'),
                ),
            'col2' => array(
                    'title' => $this->view->t('trang thai'),
                ),
            'col3' => array(
                    'title' => $this->view->t('ngay tao'),
                ),
            'col4' => array(
                    'title' => $this->view->t('chinh sua'),
                ),
            'col5' => array(
                    'title' => $this->view->t('thao tac'),
                ),
            'col6' => array(
                    'title' => $this->view->t('sep thu tu'),
                ),
        );
    }
}


